import { Controller, Request, Post, UseGuards, Get } from '@nestjs/common';

import { User } from '@src/user/entity/user.entity';
import { IsPublic } from '@src/common/decorator/is-public.decorator';

import { LocalAuthGuard } from './guard/local-auth.guard';
import { AuthService } from './auth.service';

@Controller('auth')
export class AuthController {
  constructor(private authService: AuthService) {}

  @Post('login')
  @UseGuards(LocalAuthGuard)
  @IsPublic()
  async login(@Request() req: { user: User }) {
    return this.authService.login(req.user);
  }

  @Get('profile')
  @IsPublic()
  getProfile(@Request() req) {
    return req.user;
  }
}
